
import jade.core.Agent;
import jade.core.behaviours.*;

import java.util.Iterator;
import java.util.Vector;
import java.io.*;
import jade.core.behaviours.*;
import jade.lang.acl.*;

public class AgentAnSintactica extends Agent
{
protected void setup()
{  
  addBehaviour(new CyclicBehaviour(this){
   String[] cuvlinie,clinie;
   boolean gasit=false;
   int index;
   AnalizaSintactica as=new AnalizaSintactica();
   String file=BlackBoard._TXT_PATH+"log.txt";
   
	public void action()
	{
	  ACLMessage msg = receive();
	  if (msg!=null) {
	
	  String linie=msg.getContent();
	  clinie = linie.split("\\|");
	  linie=clinie[0];
	  index=Integer.parseInt(clinie[1]);
	  cuvlinie=linie.split(" ");
	
	  //analizeaza sintactic linia
	  try{
	      gasit=as.verifica(cuvlinie, index);
	     }catch(Exception e) {WriteFile.write("Exceptie2 la linia " +index+ " "+linie,file);}
		
      // daca a trecut de analiza sintactica si cea lexicala adauga in blackboard
	  if(gasit==true){ BlackBoard.add(linie);	} else WriteFile.write("Eroare sintactica la linia " +index+ " "+linie,file);
	}		
	block(100);
	}
	});
	
}

}